package com.azkj.album.view.widgets.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.azkj.album.R;
import com.azkj.album.view.widgets.DownLoadProgressbar;


public class UploadImgDialog extends BaseDialog {

    private TextView noticeTv;
    private ImageView uploadIv;
    private DownLoadProgressbar progressBar;

    private Context mContext;


    public UploadImgDialog(Context context) {
        super(context);
        this.mContext = context;
        View content = LayoutInflater.from(context).inflate(R.layout.dialog_upload_img, null);
        uploadIv = content.findViewById(R.id.iv_upload);
        noticeTv = content.findViewById(R.id.tv_notice);
        progressBar = content.findViewById(R.id.progressBar);
        content.setOnClickListener(v -> dismiss());
        setDialogView(content);
        uploadIv.setOnClickListener(v -> {
            reset();
            showDialog();
        });
    }

    public interface ClickCallback {
        void onCamera();

        void onPhoto();
    }

    public void setProgress(int currentProgress) {
        progressBar.setProgressCurrent(currentProgress);
    }

    public void reset() {
        progressBar.setProgressCurrent(0);
        progressBar.setVisibility(View.VISIBLE);
        noticeTv.setVisibility(View.GONE);
    }


    public void setNotice(String notice) {
        noticeTv.setText(notice);
        noticeTv.setVisibility(TextUtils.isEmpty(notice) ? View.GONE : View.VISIBLE);
        progressBar.setVisibility(TextUtils.isEmpty(notice) ? View.VISIBLE : View.GONE);

    }

    private ClickCallback callback;

    public void setClickCallback(ClickCallback callback) {
        this.callback = callback;
    }

    private void showDialog() {
        String[] sexItem = new String[]{"拍照", "从相册选择"};
        BottomDialog bottomDialog = new BottomDialog(mContext);
        bottomDialog.initDialog(null, null, sexItem, (view, which, l) -> {
            if (which == 0) {
                if (callback != null) callback.onCamera();
            } else if (which == 1) {
                if (callback != null) callback.onPhoto();
            }
            bottomDialog.dismissDialog();

        });

        bottomDialog.showDialog();
    }


}
